// 加载table 数据
$(function(){
	var goBackFlag = $("#goBackFlag").val();
	var flag = sessionStorage.getItem("index"); // 缓存的 flag
	flag = (flag == null) ? 0 : flag ; // 初始 flag == 0
	$("#myTabContent").children().eq(flag).show().siblings().hide(); // 判断该显示页面那个 box 框
	$("#myTabs").children().eq(flag).addClass("active").siblings().removeClass("active"); // 判断该给那个标签加 active
	//页面加载子订单返回按钮到当前TAB页面
	if (goBackFlag == 1) {
		$("#myTabContent").children().eq(1).show().siblings().hide(); // 判断该显示页面那个 box 框
		$("#myTabs").children().eq(1).addClass("active").siblings().removeClass("active"); // 判断该给那个标签加 active
		$(".idClass").bootstrapTable({ 
	    	url: "/orderUrl/idList.json?random=" + Math.random(),
	    	method:"get", 
	    	pagination:true,
	    	sidePagination:"server",
	    	cache:false,
	    	queryParams: function(params) {
	            return $.extend({}, params, parseJson(decodeURIComponent($(".idClassFrom").serialize())));     
	        }
   		});
	}
	if (flag == 0){
		$(".linkClass").bootstrapTable({ 
	    	url: "/orderUrl/list.json?random=" + Math.random(),
	    	method:"get", 
	    	pagination:true,
	    	sidePagination:"server",
	    	cache:false,
	    	queryParams: function(params) {
	            return $.extend({}, params, parseJson(decodeURIComponent($(".linkClassFrom").serialize())));     
	        }
   		});
   		sessionStorage.removeItem("index");
	} else if (flag == 1){
		$(".idClass").bootstrapTable({ 
	    	url: "/orderUrl/idList.json?random=" + Math.random(),
	    	method:"get", 
	    	pagination:true,
	    	sidePagination:"server",
	    	cache:false,
	    	queryParams: function(params) {
	            return $.extend({}, params, parseJson(decodeURIComponent($(".idClassFrom").serialize())));     
	        }
   		});
   		sessionStorage.removeItem("index");
	} else {
		//暂无业务
	}
})
function buttonFormatter(value, row, index) {
	var caozuo = "<button id='btn_edit' type='button' onclick='orderSon_list("+row.tlzsRowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-eye-open'></span>订单完成详情</button>";
	return caozuo;
}
//url类型
function urlTypeFormatter(value, row) {
	if (row.urlType == 1) {
		return "<a href='#' onclick='lookOver(\""+row.PROPERTY_VALUE+"\");'>球球大作战/贪吃蛇大作战</a>";
	} else {
		return "<a href='#' onclick='lookOver(\""+row.PROPERTY_VALUE+"\");'>欢乐球吃球</a>";
	}
}
//赠送内容
function gameTypeFormatter(value, row) {
	if (row.gameType == 1) {
		return "棒棒糖";
	} else if (row.gameType == 2) {
		return "龙蛋";
	} else if (row.gameType == 3) {
		return "金币";
	} else if (row.gameType == 4){
		return "星贝";
	} else if (row.gameType == 5) {
		return "爱心";
	} else if (row.gameType == 6) {
		return "粉丝";
	} else if (row.gameType == 0) {
		return "点赞";
	}
}

//查看链接
function lookOver(PROPERTY_VALUE){
	var base = new Base64();
	var encodeStr = base.encode(PROPERTY_VALUE);
	layer.open({
 	  	type: 2,
	 	title: "查看链接信息",
 	  	closeBtn: 1,
 	  	shadeClose: true,
 	  	area: ['450px','230px'],
 	  	content: '/orderUrl/lookOver?propertyValue='+encodeStr,
 	  	btn: ["关 闭"]
	});
}
//订单完成详情
function orderSon_list(tlzsRowId){
	$.ajax({
		type: "post",
		cache: false,
		url: "/orderUrl/checkSonOrderNum",
		data:{tlzsRowId:tlzsRowId},
		dataType:"json",
		async:false,
		success: function(data) {
			if (data == 1) { 
				layer.msg("该订单当前没有完成信息");
				return;
			} else {
				window.location.href="/orderUrl/orderSonList?tlzsRowId="+tlzsRowId;
			}
		}
	});
}
/* 标签切换  */
$("#myTabs").children().click(function(){
	sessionStorage.setItem("index",$(this).index()); // 存 flag
	$("#flag").val(sessionStorage.setItem("index",$(this).index()));
	loadLinkOrderList($(this).index()); // 页面跳转(其实没跳转，只是刷新 #冯宝春没脑子#)
})
//查询
function findData(){
	//链接查询关键
	var link = $("#PROPERTY_VALUE_LINK").val();
	var baseLink = new Base64();
	var encodeStrLink = baseLink.encode(link);
	if (encodeStrLink.indexOf("=") > 0) {
		var newEncodeStrLink = encodeStrLink.replace(/=/g, "等号");
		$('input[name="wm[b.PROPERTY_VALUE]').val(newEncodeStrLink);
	} else {
		$('input[name="wm[b.PROPERTY_VALUE]').val(encodeStrLink);
	}
	$(".linkClass").bootstrapTable("refresh",{} );
	//id查询关键
	var ID = $("#PROPERTY_VALUE_ID").val();
	var baseId = new Base64();
	var encodeStrId = baseId.encode(ID);
	if (encodeStrId.indexOf("=") > 0) {
		var newEncodeStrId = encodeStrId.replace(/=/g, "等号");
		$('input[name="wm[p.PROPERTY_VALUE]').val(newEncodeStrId);
	} else {
		$('input[name="wm[p.PROPERTY_VALUE]').val(encodeStrId);
	}
	$(".idClass").bootstrapTable("refresh",{} ); 
}
function loadLinkOrderList(flag) {
	window.location.href="/orderUrl/list?flag=" + flag;
}
/*bootstrap table点击行事件*/ 
$(function(){
	 $("body").on("click","table>tbody>tr",function(){
      $(this).css("background","#e1ecf1").siblings().css("background","");
   });
})

